--[[
-- disabled till working properly. too buggy atm
function gadget:GetInfo()
    return {
        name = "run",
        desc = "Unit can enable a running mode",
        author = "Alfred Franz",
        date = "January 2009",
        license = "GNU GPL v2, or later",
        layer = 3, -- watchout for which layer!
        enabled = true
    }
end

local knight=UnitDefNames.knight.id
local bishop=UnitDefNames.bishop.id
local rook=UnitDefNames.rook.id
local queen=UnitDefNames.queen.id       -- want to make independent of this really - be called from Bishop.lua (same is valid for Jump!!)
                                        -- oh rly ? perhapns not better if we have the button/ UI side handled here in the Ability Gadget, and just get it's level from the individual one? dunno...
local runCapable= { [bishop]=true,
					[knight]=true,
					[rook]=true,
					[queen]=true}       -- if I really use this everywhere, might want to import from one place...

local CMD_WALK = 131232131   -- command ID

local COBRATIO = 1/30*65535
local RUN_MULTIFIER = 2

-- use these values if we stick with the current solution (so that have different engine speeds)
-- just can't get it to work atm...
-- local RUN_MULTIFIER = { [bishop]=1.4,
					-- [knight]=2,
					-- [rook]=1.75,
					-- [queen]=2} 


local runDescRun = {      --settings for the stun button
    name="walking",
    tooltip="run",
    action="run",
    id=CMD_WALK,
    type=CMDTYPE.ICON
}

local runDescWalk = {      --settings for the stun button
    name="running",
    tooltip="walk",
    action="walk",
    id=CMD_WALK,
    type=CMDTYPE.ICON
}


if (gadgetHandler:IsSyncedCode()) then
--SYNCED

local run = {}
local comesOut = {}

function gadget:GameFrame(f)

	for unitID,runBool in pairs(run) do
		if ((runBool) and (Spring.GetUnitVelocity(unitID)~=0)) then
			Spring.SetUnitWeaponState(unitID, 0 ,{reloadState=100000})
			Spring.SetUnitWeaponState(unitID, 1 ,{reloadState=100000})
			comesOut[unitID] = true
		else
			if (comesOut[unitID]) then
				comesOut[unitID] = false
				Spring.SetUnitWeaponState(unitID, 0 ,{reloadState=0})
				Spring.SetUnitWeaponState(unitID, 1 ,{reloadState=0})
			end
		end
	end

end


function gadget:UnitCreated(unitID, unitDefID, teamID)
    if runCapable[unitDefID] then
        Spring.InsertUnitCmdDesc(unitID,runDescRun) -- insert button
        comesOut[unitID] = false
        run[unitID] = false
        Spring.SetUnitCOBValue(unitID,75,(UnitDefs[Spring.GetUnitDefID(unitID)].speed * COBRATIO / RUN_MULTIFIER))
    end
end

function gadget:CommandFallback(unitID, unitDefID, teamID, cmdID, cmdParams, cmdOptions, cmdTag)
	if cmdID == CMD_WALK then
	    if run[unitID] then
            Spring.EditUnitCmdDesc(unitID,Spring.FindUnitCmdDesc(unitID, CMD_WALK),runDescRun)
            Spring.SetUnitCOBValue(unitID,75,(UnitDefs[Spring.GetUnitDefID(unitID)].speed * COBRATIO / RUN_MULTIFIER))
            run[unitID] = false
       else
            Spring.EditUnitCmdDesc(unitID,Spring.FindUnitCmdDesc(unitID, CMD_WALK),runDescWalk)
            Spring.SetUnitCOBValue(unitID,75,(UnitDefs[Spring.GetUnitDefID(unitID)].speed * COBRATIO * RUN_MULTIFIER))
            --REPLACE IN NEXT SPRING VERSION: Spring.MoveCtrl.SetGroundMoveTypeData(unitID,{maxSpeed=1000})
            run[unitID] = true
       end
   end
end

end
--]]